﻿Imports System
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Xml.Serialization
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.WebPartPages
Imports Microsoft.SharePoint.WebControls
Imports Microsoft.SharePoint.Utilities
Imports System.Text

Public Class CountdownTP
    Inherits Microsoft.SharePoint.WebPartPages.ToolPart
    Private dp As DateTimeControl
    Private chkDays As CheckBox
    Private chkHours As CheckBox
    Private chkMins As CheckBox
    Private chkSecs As CheckBox
    Private txtLink As TextBox
    Private txtTitle As TextBox
    Private txtDesc As TextBox

    Public Overrides Sub ApplyChanges()
        Try

            Dim wp As CountdownWebPart.CountdownWP = CType(Me.ParentToolPane.SelectedWebPart, CountdownWebPart.CountdownWP)
            wp.CountdownDateTime = dp.SelectedDate
            wp.showDays = chkDays.Checked.ToString
            wp.showHours = chkHours.Checked.ToString
            wp.showMins = chkMins.Checked.ToString
            wp.showSecs = chkSecs.Checked.ToString
            wp.infoLink = txtLink.Text
            wp.infoText = txtTitle.Text
            wp.CountdownDesc = txtDesc.Text

        Catch ex As Exception

            Page.Response.Write(ex.ToString)

        End Try

    End Sub

    Public Overrides Sub SyncChanges()
    End Sub

    Public Overrides Sub CancelChanges()
    End Sub

    Protected Overrides Sub RenderToolPart(ByVal output As System.Web.UI.HtmlTextWriter)
        MyBase.RenderToolPart(output)
    End Sub

    Protected Overrides Sub CreateChildControls()

        Dim wp As CountdownWebPart.CountdownWP = CType(Me.ParentToolPane.SelectedWebPart, CountdownWebPart.CountdownWP)

        Controls.Add(New LiteralControl("<p>Enter the date & time you're counting down to:<br/>"))

        dp = New DateTimeControl
        dp.DateOnly = False
        dp.LocaleId = SPContext.Current.RegionalSettings.LocaleId
        dp.HoursMode24 = True

        If wp.CountdownDateTime = Nothing Then
            dp.SelectedDate = Now
        Else
            dp.SelectedDate = wp.CountdownDateTime
        End If

        Controls.Add(dp)

        Controls.Add(New LiteralControl("</p><p>Show Days<br>"))

        chkDays = New CheckBox

        If Not wp.showDays = Nothing Then
            chkDays.Checked = wp.showDays
        End If

        Controls.Add(chkDays)

        Controls.Add(New LiteralControl("</p><p>Show Hours<br>"))

        chkHours = New CheckBox

        If Not wp.showHours = Nothing Then
            chkHours.Checked = wp.showHours
        End If

        Controls.Add(chkHours)

        Controls.Add(New LiteralControl("</p><p>Show Minutes<br>"))

        chkMins = New CheckBox

        If Not wp.showMins = Nothing Then
            chkMins.Checked = wp.showMins
        End If

        Controls.Add(chkMins)

        Controls.Add(New LiteralControl("</p><p>Show Seconds<br>"))

        chkSecs = New CheckBox

        If Not wp.showSecs = Nothing Then
            chkSecs.Checked = wp.showSecs
        End If

        Controls.Add(chkSecs)

        Controls.Add(New LiteralControl("</p>"))

        Controls.Add(New LiteralControl("<p>Enter a URL to link to<br>"))

        txtLink = New TextBox
        If Not wp.infoLink = Nothing Then
            txtLink.Text = wp.infoLink
        End If
        Controls.Add(txtLink)

        Controls.Add(New LiteralControl("</p>"))
        Controls.Add(New LiteralControl("<p>Enter some text for the link<br>"))

        txtTitle = New TextBox
        If Not wp.infoText = Nothing Then
            txtTitle.Text = wp.infoText
        End If
        Controls.Add(txtTitle)


        Controls.Add(New LiteralControl("</p>"))
        Controls.Add(New LiteralControl("<p>Enter a description of what is being ""counted down""<br>"))

        txtDesc = New TextBox
        txtDesc.Rows = 10
        txtDesc.Columns = 30
        txtDesc.TextMode = TextBoxMode.MultiLine

        If Not wp.CountdownDesc = Nothing Then
            txtDesc.Text = wp.CountdownDesc
        End If

        Controls.Add(txtDesc)

        Controls.Add(New LiteralControl("</p>"))

        MyBase.CreateChildControls()
    End Sub



End Class
